package zero.tech.games.gate.mapper;

import java.util.List;

import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Options;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

import zero.tech.games.entity.games.ClubGameRule;

public interface ClubGameRuleMapper {

	@Select("select * from club_game_rule where rule_id=#{rule_id}")
	ClubGameRule getClubGameRule(@Param("rule_id")int rule_id);

	@Select("select * from club_game_rule where club_id=#{club_id} and open=1")
	List<ClubGameRule> loadClubGameRulesByClubId(@Param("club_id")int club_id);

	@Insert("insert into club_game_rule(pipei_key,class_name,club_id,game_id,config_str,open,fzb_playernum) "
			+ "values(#{pipei_key},#{class_name},#{club_id},#{game_id},#{config_str},#{open},#{fzb_playernum})")
	@Options(useGeneratedKeys = true,keyProperty = "rule_id")
	void insert(ClubGameRule clubGameRule);

	@Select("select count(1) from club_game_rule where club_id=#{club_id} and class_name=#{class_name} and open in (0,1)")
	int loadGameRuleTotalCountByPage(@Param("club_id")int club_id,@Param("class_name") String class_name);

	@Select("select * from club_game_rule where club_id=#{club_id} and class_name=#{class_name} and open in (0,1) order by open desc limit #{start},#{pageLength}")
	List<ClubGameRule> loadGameRulesByPage(@Param("club_id")int club_id,@Param("class_name") String class_name, @Param("start")int start, @Param("pageLength")int pageLength);

	@Update("update club_game_rule set open=#{open} where rule_id=#{rule_id}")
	void updateSwitch(@Param("rule_id")int rule_id,@Param("open") int open);

}
